import { Injectable } from '@angular/core';
import { StateMachineService } from "@farris/command-services";
import { FrameContext } from '@farris/devkit';
import { BefRepository, ResponseInfo } from '@farris/bef';
import { FormMessageService, FormNotifyService, CommandService, FormLoadingService, BeActionService } from '@farris/command-services';
import { EMPTY, of } from 'rxjs';
import { tap, map, switchMap } from 'rxjs/operators';

@Injectable()
export class GzlxsqformFrmControllerService {
  constructor(
    private frameContext: FrameContext,
    private messageService: FormMessageService,
    private beActionService: BeActionService,
    public stateMachineService: StateMachineService,
    public formNotifyService: FormNotifyService,
    private commandService: CommandService,
    public loadingService: FormLoadingService
  ) { }

  /**
   * 保存工装信息
   * @remarks 
   * @returns 
   */
  savegzxx(): any {
    const context = this.frameContext;
    let id = context.bindingData.getValue(['id'])
    const rep = this.frameContext.repository as BefRepository<any>;
    const datas = this.frameContext.uiState['datas'];
    let gzxxdata = []
    debugger
    for (let item of datas) {
      const id = item.data.id;
      const name = item.data.name;
      const ysdm = item.data.ysdm;
      const dw = item.data.dw;
      gzxxdata.push({
        gzxxid: {
          gzxxid: id,
          gzxxid_name: name,
          gzxxid_ysdm: ysdm,
          gzxxid_dw: dw,
        }
      })
    }
    // gzlxsqmx
    rep.batchAppendByPath('/' + id + '/gzlxsqmxs', gzxxdata).subscribe()

  }

  /**
   * 附件扩展按钮点击事件
   * @remarks 
   * @returns 
   */
  fjFileNameInputAppendClickEvent(): any {
    let eventParam = this['context'].eventParam;
    let clickid = eventParam.event.target.getAttribute('id');
    if (clickid === "cardforntview") {
      return this.commandService.execute('basicformPreviewByAttachmentInfoFieldPath1', 'basic-form-component');
    }
    else if (clickid === "cardforntdownload") {
      return this.commandService.execute('basicformDownload1', 'basic-form-component');
    }
  }
}
